package com.example.kill.controller;

import com.alibaba.fastjson.JSON;
import com.example.kill.result.CodeMsg;
import com.example.kill.result.Result;
import com.example.kill.service.KillUserService;
import com.example.kill.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
public class LoginController {

    private static Logger LOGGER = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private KillUserService userService;



    @RequestMapping("/to_login")
    public String toLogin(){
        return "login";
    }



    @RequestMapping("/do_login")
    @ResponseBody
    public Result<Boolean> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
        LOGGER.info("loginVo={}", JSON.toJSON(loginVo));
        userService.login(response,loginVo);
        return Result.success(true);
    }


}
